package com.project.controller.customer;

import com.project.bean.ShopCartBean;
import com.project.bean.UserBean;
import com.project.service.IShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("customer/shop")
@RestController
public class ShopCartController {
    @Autowired
    private IShopCartService shopCartService;

    @RequestMapping("buy")
    public String buy(Integer productId,HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        shopCartService.add(productId,user.getId());
        return "ok";
    }

    @RequestMapping("findShopCart")
    public List<ShopCartBean> findShopCart(HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return shopCartService.findAll(user.getId());
    }

    @RequestMapping("del")
    public String del(int shopCartId){
        shopCartService.del(shopCartId);
        return "ok";
    }

    @RequestMapping("update")
    public String update(int shopCartId,int count){
        shopCartService.updateCount(shopCartId,count);
        return "ok";
    }
}
